package com.jzg.jcptadmin.ui;

import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bigkoo.convenientbanner.ConvenientBanner;
import com.bigkoo.convenientbanner.holder.CBViewHolderCreator;
import com.bigkoo.convenientbanner.holder.Holder;
import com.bigkoo.convenientbanner.listener.OnItemClickListener;
import com.jakewharton.rxbinding.view.RxView;
import com.jzg.jcptadmin.R;
import com.jzg.jcptadmin.Utils.MyToast;
import com.jzg.jcptadmin.Utils.ScreenUtils;
import com.jzg.jcptadmin.adpter.FastOnLineStatusAdapter;
import com.jzg.jcptadmin.base.BaseActivity;
import com.jzg.jcptadmin.constant.Constant;
import com.jzg.jcptadmin.data.DataManager;
import com.jzg.jcptadmin.data.local.LocalData;
import com.jzg.jcptadmin.data.vo.CarDetails;
import com.jzg.jcptadmin.data.vo.StatusData;
import com.jzg.jcptadmin.data.vo.SuccessData;
import com.jzg.jcptadmin.data.vo.User;
import com.jzg.jcptadmin.presenter.OperationPresenter;
import com.jzg.jcptadmin.view.ActionSheet;
import com.jzg.jcptadmin.view.MarqueeText;
import com.jzg.jcptadmin.view.MyScrollview;
import com.jzg.jcptadmin.viewinterface.OperationInterface;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.orhanobut.logger.Logger;
import com.tbruyelle.rxpermissions.Permission;
import com.tbruyelle.rxpermissions.RxPermissions;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import butterknife.Bind;
import butterknife.BindString;
import butterknife.ButterKnife;
import butterknife.OnClick;
import cn.pedant.SweetAlert.SweetAlertDialog;
import rx.functions.Action1;

/**
 * 快速线上任务详情页面
 * FastOnlineCheckActivity
 * 评估师18张列表详情  第三方机构鉴定结果列表详情
 *
 * @author sunbl
 *         created at 2016/1/21 16:07
 */
public class FastOnlineCheckActivity1 extends BaseActivity implements View.OnClickListener,
        ActionSheet.OnActionSheetSelected,
        DialogInterface.OnCancelListener, OperationInterface {
    //    @Bind(R.id.pic_gridview)
//    RecyclerView picGridview;
    @Bind(R.id.convenientBanner)
    ConvenientBanner convenientBanner;
    @Bind(R.id.isshowPrice)
    LinearLayout isshowPrice;
    @Bind(R.id.tv_vin1)
    TextView tvVin;
    @Bind(R.id.tv_chengjiaojia)
    TextView chengjiaojiaShow;
    @Bind(R.id.ll_pinggu)
    LinearLayout llPinggu;
    @Bind(R.id.ll_c2b)
    LinearLayout llC2b;
    @Bind(R.id.ll_b2c)
    LinearLayout llB2c;
    @Bind(R.id.tv_editdes)
    TextView tvEditdes;
    @Bind(R.id.ll_edit)
    LinearLayout llEdit;
    @Bind(R.id.myScrollview)
    MyScrollview myScrollview;
    @Bind(R.id.tv_brand_content)
    MarqueeText tvBrandContent;
    @Bind(R.id.tv_changshangzhidao)
    TextView tvChangshangzhidao;
    @Bind(R.id.tv_ranliao)
    TextView tvRanliao;
    @Bind(R.id.tv_pailiang)
    TextView tvPailiang;
    @Bind(R.id.tv_cartype)
    TextView tvCartype;
    @Bind(R.id.tv_biansuqi)
    TextView tvBiansuqi;
    @Bind(R.id.tv_people)
    TextView tvPeople;
    @Bind(R.id.card_date_content)
    TextView cardDateContent;
    @Bind(R.id.tv_chuchangdata)
    TextView tvChuchangdata;
    @Bind(R.id.tv_pinpaixh)
    TextView tvPinpaixh;
    @Bind(R.id.tv_carnum)
    TextView tvCarnum;
    @Bind(R.id.tv_shiyongxz)
    TextView tvShiyongxz;
    @Bind(R.id.tv_carcolor)
    TextView tvCarcolor;
    @Bind(R.id.tv_fdjnum)
    TextView tvFdjnum;
    @Bind(R.id.area_content)
    TextView areaContent;
    @Bind(R.id.mileage_content)
    TextView mileageContent;
    @Bind(R.id.km)
    TextView km;
    @Bind(R.id.beizhu)
    TextView beizhu;
    @Bind(R.id.car_beizhu_text_show)
    TextView carBeizhuTextShow;
    @Bind(R.id.appraiseDes)
    TextView appraiseDes;
    @Bind(R.id.price_pinggu)
    TextView pricePinggu;
    @Bind(R.id.price_pingguc2b)
    TextView pricePingguc2b;
    @Bind(R.id.price_pinggub2c)
    TextView pricePinggub2c;
    @Bind(R.id.price_linear)
    LinearLayout priceLinear;
    @Bind(R.id.tv_tuihuiyy)
    TextView tvTuihuiyy;
    @Bind(R.id.tv_fadan)
    TextView tvFadan;
    @Bind(R.id.tv_fadanphone)
    TextView tvFadanphone;
    @Bind(R.id.ranliao)
    TextView ranliao;
    @Bind(R.id.biansuqi)
    TextView biansuqi;
    @Bind(R.id.pinpaixinghao)
    TextView pinpaixinghao;
    @Bind(R.id.fadongji)
    TextView fadongji;
    @Bind(R.id.iv_jisudai)
    ImageView ivJisudai;
    @Bind(R.id.title_content)
    TextView titleContent;
    @Bind(R.id.tv_right)
    TextView tvRight;
    @Bind(R.id.tv_jigou)
    TextView tvJigou;
    @Bind(R.id.iv_call)
    ImageView ivCall;
    @Bind(R.id.rl_bxlc)
    RelativeLayout rlBxlc;
    @Bind(R.id.pic_item)
    ImageView picItem;
    private PopupWindow pwMyPopWindow;
    private ListView lvPopupList;
    private ArrayList<Map<String, String>> moreList;
    //    private int NUM_OF_VISIBLE_LIST_ROWS = 3;// 指定popupwindow中Item的数量
    public CarDetails details;
    public StatusData.ItemListEntity.FastOnLineBtnEntity status;
    private FastOnLineStatusAdapter fastOnLineStatusAdapter;
    private List<String> statusList;
    private OperationPresenter operationPresenter;
    private User user;
    private RxPermissions rxPermissions;

    private String orderStatus; //订单状态
    private String isAccident; // 事故车辆

    @BindString( R.string.accident_tip )
    String accidentTip;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_fast_online_check1);
        ButterKnife.bind(this);
        titleContent.setText("任务查看");
        tvRight.setText("操作");
        ViewGroup.LayoutParams params = convenientBanner.getLayoutParams();
        params.width = RadioGroup.LayoutParams.MATCH_PARENT;
        params.height = ScreenUtils.getScreenWidth(this) * 9 / 16;
        convenientBanner.setLayoutParams(params);
        //操作的状态
        if(appContext.getStatus()==null||appContext.getStatus().getItemList()==null||appContext.getStatus().getItemList().getFastOnLineBtn()==null){
            MyToast.showShort("请重新登录");
            return;
        }
        status = appContext.getStatus().getItemList().getFastOnLineBtn();
        user = appContext.getUser();
        operationPresenter = new OperationPresenter(DataManager.getInstance());
        operationPresenter.attachView(this);
        details = getIntent().getParcelableExtra("carDetails");
        if (details != null) {
            init();
        }
        orderStatus = getIntent().getStringExtra(Constant.ORDER_STATUS);
        isAccident = getIntent().getStringExtra(Constant.VIN_STATE);
        initdata();//获取操作的条件
        iniPopupWindow();
        checkVinState();
    }

    /**
     * 检查当前Vin是否在黑名单列表里
     */
    private void checkVinState(){

        if (!(("1").equals(isAccident) && !TextUtils.isEmpty(orderStatus) && orderStatus.compareTo("2") < 0 )) //事故车辆，并且订单状态是未评估
            return;
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(400);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        showVinWarningDialog();
                    }
                });

            }
        }).start();
    }

    private void showVinWarningDialog(){
        SweetAlertDialog alertDialog = new SweetAlertDialog(FastOnlineCheckActivity1.this);
        alertDialog.setTitleText(accidentTip);
        alertDialog.setContentText("    ");
        alertDialog.setConfirmText("知道了");
        alertDialog.setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
            @Override
            public void onClick(SweetAlertDialog sweetAlertDialog) {
                sweetAlertDialog.dismiss();
            }
        });
        alertDialog.setCancelable(false);
        alertDialog.show();

    }

    private void initdata() {
        statusList = new ArrayList<>();
        //获取操作的筛选条件
        String[] str = details.getButtonStr().split(",");
        List<StatusData.ItemListEntity.FastOnLineBtnEntity.ItemEntity> itemEntityList = status.getItem();
        for (int i = 0; i < itemEntityList.size(); i++) {
            for (int j = 0; j < str.length; j++) {
                if (itemEntityList.get(i).getId().equals(str[j])) {
                    statusList.add(itemEntityList.get(i).getValue());
                }
            }
        }

        if (statusList.size() <= 0) {
            tvRight.setVisibility(View.GONE);
        } else {
            tvRight.setVisibility(View.VISIBLE);
        }
    }

    private void iniPopupWindow() {
        LayoutInflater inflater = (LayoutInflater) this
                .getSystemService(LAYOUT_INFLATER_SERVICE);
        View layout = inflater.inflate(R.layout.task_detail_popupwindow, null);
        lvPopupList = (ListView) layout.findViewById(R.id.lv_popup_list);
        pwMyPopWindow = new PopupWindow(layout);
        pwMyPopWindow.setFocusable(true);// 加上这个popupwindow中的ListView才可以接收点击事件
        if (fastOnLineStatusAdapter == null) {
            fastOnLineStatusAdapter = new FastOnLineStatusAdapter(appContext, statusList);
        }
        lvPopupList.setAdapter(fastOnLineStatusAdapter);
        lvPopupList.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                //点击操作回调,筛选操作的功能
                ScreenOperation(statusList.get(position));
                pwMyPopWindow.dismiss();
            }
        });
        // 控制popupwindow的宽度和高度自适应
        lvPopupList.measure(View.MeasureSpec.UNSPECIFIED,
                View.MeasureSpec.UNSPECIFIED);
        pwMyPopWindow.setWidth(lvPopupList.getMeasuredWidth());
        /*pwMyPopWindow.setHeight((lvPopupList.getMeasuredHeight() + 20)
                * NUM_OF_VISIBLE_LIST_ROWS);*/
        pwMyPopWindow.setHeight((lvPopupList.getMeasuredHeight() + 20)
                * (statusList.size() + 1));
        // 控制popupwindow点击屏幕其他地方消失
        pwMyPopWindow.setBackgroundDrawable(this.getResources().getDrawable(
                R.drawable.bg_tanchu));// 设置背景图片，不能在布局中设置，要通过代码来设置
        pwMyPopWindow.setOutsideTouchable(true);// 触摸popupwindow外部，popupwindow消失。这个要求你的popupwindow要有背景图片才可以成功，如上
    }

    public void ScreenOperation(String string) {
        switch (string) {
            case "重发":
                new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
                        .setTitleText("提示")
                        .setContentText("您确定要重发这条数据？")
                        .setConfirmText("是的").setCancelText("取消")
                        .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sDialog) {
                                showDialog();
                                operationPresenter.OperationData("chongfa", details.getCarId(), "", "", "", String.valueOf(appContext.getUser().getUserId()));
                                sDialog.dismissWithAnimation();
                            }
                        }).show();

                break;
            case "查看":
                //operationPresenter.OperationData("chongfa",details.getCarId(),"","","");
                break;
//            case "修改":
//                new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
//                        .setTitleText("提示")
//                        .setContentText("您确定要修改这条数据？")
//                        .setConfirmText("是的").setCancelText("取消")
//                        .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
//                            @Override
//                            public void onClick(SweetAlertDialog sDialog) {
//                                Intent intent = new Intent(FastOnlineCheckActivity1.this, AddTaskActivity.class);
//                                intent.putExtra(Constant.ACTIVITY_KUAISUDATA, details);
//                                startActivity(intent);
//                                sDialog.dismissWithAnimation();
//                            }
//                        }).show();
//                break;
            case "删除":

                new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
                        .setTitleText("提示")
                        .setContentText("您确定要删除这条数据吗？")
                        .setConfirmText("是的").setCancelText("取消")
                        .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sDialog) {
                                showDialog();
                                operationPresenter.OperationData("del", details.getCarId(), "", "", "", String.valueOf(appContext.getUser().getUserId()));
                                sDialog.dismissWithAnimation();
                            }
                        }).show();
                break;
            case "评估":
                Intent intent2 = new Intent(this, EvaluationActivity.class);
                intent2.putExtra("details", details);
                startActivity(intent2);
//                operationPresenter.OperationData("pinggu", details.getCarId(), "", details.getAppraise(), details.getAppraiseDes());
                break;
            case "审核通过":
                new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
                        .setTitleText("提示")
                        .setContentText("您确定要通过这条数据？")
                        .setConfirmText("是的").setCancelText("取消")
                        .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sDialog) {
                                showDialog();
                                operationPresenter.OperationData("shenhe", details.getCarId(), "", "", "", String.valueOf(appContext.getUser().getUserId()));
                                sDialog.dismissWithAnimation();
                            }
                        }).show();
                break;
            case "退回":
                Intent intent4 = new Intent(this, RejectActivity.class);
                intent4.putExtra("id", details.getCarId());
                intent4.putExtra("status", "退回");
                startActivity(intent4);
                break;
            case "恢复":
                showDialog();
                operationPresenter.OperationData("huifu", details.getCarId(), "", "", "", String.valueOf(appContext.getUser().getUserId()));
                new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
                        .setTitleText("提示")
                        .setContentText("您确定要恢复这条数据？")
                        .setConfirmText("是的").setCancelText("取消")
                        .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sDialog) {
                                showDialog();
                                operationPresenter.OperationData("huifu", details.getCarId(), "", "", "", String.valueOf(appContext.getUser().getUserId()));
                                sDialog.dismissWithAnimation();
                            }
                        }).show();
                break;
            case "签收":

                new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
                        .setTitleText("提示")
                        .setContentText("您确定要通过这条数据？")
                        .setConfirmText("是的").setCancelText("取消")
                        .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sDialog) {
                                showDialog();
                                operationPresenter.OperationData("qianshou", details.getCarId(), "", "", "", String.valueOf(appContext.getUser().getUserId()));
                                sDialog.dismissWithAnimation();
                            }
                        }).show();

                break;
            case "审核驳回":
                Intent intent3 = new Intent(this, RejectActivity.class);
                intent3.putExtra("id", details.getCarId());
                intent3.putExtra("status", "审核驳回");
                intent3.putExtra("details", details);
                startActivity(intent3);
                break;
            case "签收驳回":
                Intent intent5 = new Intent(this, RejectActivity.class);
                intent5.putExtra("id", details.getCarId());
                intent5.putExtra("status", "签收驳回");
                startActivity(intent5);
                break;
            case "转到线下":
                new SweetAlertDialog(this, SweetAlertDialog.WARNING_TYPE)
                        .setTitleText("提示")
                        .setContentText("您确定要将这条数据转到线下？")
                        .setConfirmText("是的").setCancelText("取消")
                        .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                            @Override
                            public void onClick(SweetAlertDialog sDialog) {
                                showDialog();
                                operationPresenter.OperationData("zhuanxianxia", details.getCarId(), "", "", "", String.valueOf(appContext.getUser().getUserId()));
                                sDialog.dismissWithAnimation();
                            }
                        }).show();
                break;


            default:

                break;
        }
    }


    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (operationPresenter != null)
            operationPresenter.detachView();
        ButterKnife.unbind(this);
    }

    private void init() {
        callPhone();
        if (TextUtils.isEmpty(details.getVideoPath())) {
            picItem.setVisibility(View.INVISIBLE);
        }else{
            picItem.setVisibility(View.VISIBLE);
        }
//        if(details.getIsNewEighteen()!=null&&!TextUtils.isEmpty(details.getIsNewEighteen())&&"1".equals(details.getIsNewEighteen())){
//            rlBxlc.setVisibility(View.GONE);
//        }else{
//            rlBxlc.setVisibility(View.VISIBLE);
//        }
        if (!TextUtils.isEmpty(details.getProductTypeImage())) {
            ImageLoader.getInstance().displayImage(details.getProductTypeImage(), ivJisudai, appContext.options);
        }
        tvVin.setText("VIN码:" + details.getVin());
        chengjiaojiaShow.setText("成交价:" + details.getBusinessPrice() + "万元");
        tvBrandContent.setText(details.getFullName());//品牌车型
        if (!TextUtils.isEmpty(details.getManufacturerPrice())) {
            tvChangshangzhidao.setText(details.getManufacturerPrice() + "万元");//厂商指导价
        }

        tvRanliao.setText(details.getFuel() == null ? details.getFuel() : details.getFuel().trim());//燃料
        if (!TextUtils.isEmpty(details.getEngine_Exhaust())) {
            tvPailiang.setText(details.getEngine_Exhaust() + "L");//排量
        }

        tvCartype.setText(details.getCarTypeName());//车辆类型
        tvPinpaixh.setText(details.getRecordBrand());//品牌型号
        tvBiansuqi.setText(details.getTransmissionType());//变速器类型
        tvPeople.setText(details.getSeating());//额定载客
        tvChuchangdata.setText(details.getProductionTime());//出厂日期
        tvCarnum.setText(details.getCarLicense());//车牌号码
        tvShiyongxz.setText(details.getServiceName());//使用性质
        tvCarcolor.setText(details.getColorName());//颜色
        tvFdjnum.setText(details.getEngineNum());//发动机号
        tvFadan.setText("发单人: " + details.getTaskOwnerName());
        tvFadanphone.setText("发单人手机: " + details.getTasktel());
        if ("1".equals(details.getShowSourceName())) {//是否显示机构名称 1 显示 0不显示
            tvJigou.setVisibility(View.VISIBLE);
            tvJigou.setText("机构名称: " + details.getSourceName());
        } else {
            tvJigou.setVisibility(View.GONE);
            tvJigou.setText("");
        }

        if (!TextUtils.isEmpty(details.getRegDateYear())) {
            cardDateContent.setText(details.getRecordDate());//登记日期
        }
        if (!TextUtils.isEmpty(details.getMileage())) {
            mileageContent.setText(details.getMileage() + "公里");//行驶里程
        }
        if (!TextUtils.isEmpty(details.getProvinceName())) {
            areaContent.setText(details.getProvinceName() + " " + details.getCityName());//上牌地区
        }
//        if (!TextUtils.isEmpty(details.getIsShowPrice())) {
//            if (details.getIsShowPrice().equals("0")) {
//                isshowPrice.setVisibility(View.GONE);
//                llPinggu.setVisibility(View.GONE);
//                llB2c.setVisibility(View.VISIBLE);
//                llC2b.setVisibility(View.VISIBLE);
//            } else {
//                try {
//                    isshowPrice.setVisibility(View.VISIBLE);
//                    if (user.getIsDL().equals("1")) {//1是第三方机构  显示一个价格
//                        llPinggu.setVisibility(View.VISIBLE);
//                        llB2c.setVisibility(View.GONE);
//                        llC2b.setVisibility(View.GONE);
//                        String str = details.getAppraise();
//                        BigDecimal bd = new BigDecimal(Double.parseDouble(str));
//                        pricePinggu.setText(bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "万元");
//                    } else {//显示两个价格
//                        String strB2C = details.getSalePriceB2C();//车商售车价
//                        String strC2B = details.getSalePriceC2B();//车商收车价
//                        BigDecimal bdB2C = new BigDecimal(Double.parseDouble(strB2C));
//                        BigDecimal bdC2B = new BigDecimal(Double.parseDouble(strC2B));
//                        llPinggu.setVisibility(View.GONE);
//                        llB2c.setVisibility(View.VISIBLE);
//                        llC2b.setVisibility(View.VISIBLE);
//                        pricePinggub2c.setText(bdB2C.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "万元");
//                        pricePingguc2b.setText(bdC2B.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "万元");
//                    }
//                /*String str = details.getAppraise();
//                BigDecimal bd = new BigDecimal(Double.parseDouble(str));
//                pricePinggu.setText(bd.setScale(2, BigDecimal.ROUND_HALF_UP).doubleValue() + "万元");*/
//                } catch (Exception e) {
//                    e.printStackTrace();
//                }
//            }
        if (details.getOperation().equals("1")) {   //显示退回原因
            tvTuihuiyy.setText("退回原因");
            llEdit.setVisibility(View.VISIBLE);
            tvEditdes.setText(details.getTaskBack());
            priceLinear.setVisibility(View.GONE);
            isshowPrice.setVisibility(View.GONE);
        } else if (details.getOperation().equals("2")) {  // 显示2个价格
            try {
                llEdit.setVisibility(View.GONE);
                priceLinear.setVisibility(View.VISIBLE);
                isshowPrice.setVisibility(View.VISIBLE);
                llPinggu.setVisibility(View.GONE);
                llB2c.setVisibility(View.VISIBLE);
                llC2b.setVisibility(View.VISIBLE);
                String strB2C = details.getSalePriceB2C();//车商售车价
                String strC2B = details.getSalePriceC2B();//车商收车价
                BigDecimal bdB2C = new BigDecimal(Double.parseDouble(strB2C));
                BigDecimal bdC2B = new BigDecimal(Double.parseDouble(strC2B));
                llPinggu.setVisibility(View.GONE);
                llB2c.setVisibility(View.VISIBLE);
                llC2b.setVisibility(View.VISIBLE);
                DecimalFormat fnum = new DecimalFormat("##0.00");
                pricePinggub2c.setText(fnum.format(bdB2C) + "万元");//售车价
                pricePingguc2b.setText(fnum.format(bdC2B) + "万元");///收车价
                appraiseDes.setText(details.getAppraiseDes());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (details.getOperation().equals("3")) {  //3 显示一个价钱
            try {
                llEdit.setVisibility(View.GONE);
                priceLinear.setVisibility(View.VISIBLE);
                isshowPrice.setVisibility(View.VISIBLE);
                llPinggu.setVisibility(View.VISIBLE);
                llB2c.setVisibility(View.GONE);
                llC2b.setVisibility(View.GONE);
                String str = details.getAppraise();
                BigDecimal bd = new BigDecimal(Double.parseDouble(str));
                DecimalFormat fnum = new DecimalFormat("##0.00");
                pricePinggu.setText(fnum.format(bd) + "万元");
                appraiseDes.setText(details.getAppraiseDes());
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else if (details.getOperation().equals("4")) { //全部不显示
            llEdit.setVisibility(View.GONE);
            priceLinear.setVisibility(View.GONE);
            isshowPrice.setVisibility(View.GONE);
        } else if (details.getOperation().equals("5")) {   //显示两个价格,显示驳回原因
            try {
                llEdit.setVisibility(View.VISIBLE);
                priceLinear.setVisibility(View.VISIBLE);
                isshowPrice.setVisibility(View.VISIBLE);
                llPinggu.setVisibility(View.GONE);
                llB2c.setVisibility(View.VISIBLE);
                llC2b.setVisibility(View.VISIBLE);
                String strB2C = details.getSalePriceB2C();//车商售车价
                String strC2B = details.getSalePriceC2B();//车商收车价
                BigDecimal bdB2C = new BigDecimal(Double.parseDouble(strB2C));
                BigDecimal bdC2B = new BigDecimal(Double.parseDouble(strC2B));
                llPinggu.setVisibility(View.GONE);
                llB2c.setVisibility(View.VISIBLE);
                llC2b.setVisibility(View.VISIBLE);
                DecimalFormat fnum = new DecimalFormat("##0.00");
                pricePinggub2c.setText(fnum.format(bdB2C) + "万元");
                pricePingguc2b.setText(fnum.format(bdC2B) + "万元");
                appraiseDes.setText(details.getAppraiseDes());
                tvTuihuiyy.setText("驳回原因");
                tvEditdes.setText(details.getAppraiseBack());
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
        appraiseDes.setText(details.getAppraiseDes());

        convenientBanner.setPages(
                new CBViewHolderCreator<NetworkImageHolderView>() {
                    @Override
                    public NetworkImageHolderView createHolder() {
                        return new NetworkImageHolderView();
                    }
                }, details.getCarPicList());

        convenientBanner.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(int position) {//查看大图
                Intent intent = new Intent(FastOnlineCheckActivity1.this, PhotoForNetActivity.class);
                intent.putExtra("piclists", details);
                intent.putExtra("position", position);
                intent.putExtra("isZonghe", true);
                startActivity(intent);
            }
        });

//        ivCall.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if(TextUtils.isEmpty(details.getTasktel())){
//                    MyToast.showShort("电话号码不能为空");
//                }else {
//                    callPhone();
//                }
//            }
//        });
    }

    class NetworkImageHolderView implements Holder<CarDetails.CarPicListEntity> {
        private ImageView imageView;
        private TextView title;

        @Override
        public View createView(Context context) {
            //你可以通过layout文件来创建，也可以像我一样用代码创建，不一定是Image，任何控件都可以进行翻页
            View view = LayoutInflater.from(context).inflate(R.layout.taskdetail_photo, null);
            imageView = (ImageView) view.findViewById(R.id.photo_img);
            title = (TextView) view.findViewById(R.id.title);
            return view;
        }

        @Override
        public void UpdateUI(Context context, int position, CarDetails.CarPicListEntity data) {
            int tag = position + 1;
            title.setText(data.getItemName18() + "(" + tag + "/" + details.getCarPicList().size() + ")");
            ImageLoader.getInstance().displayImage
                    (data.getPath(), imageView, appContext.options);
        }
    }

    @OnClick({R.id.tv_right, R.id.pic_item})
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_right://操作
                if (pwMyPopWindow != null && pwMyPopWindow.isShowing()) {
                    pwMyPopWindow.dismiss();// 关闭
                } else {
                    if (pwMyPopWindow != null)
                        pwMyPopWindow.showAsDropDown(tvRight);// 显示
                }
                break;
//            case R.id.tv_huifu://操作
//                String content = etContent.getText().toString();
//                if (TextUtils.isEmpty(content)) {
//                    Toast.makeText(FastOnlineCheckActivity.this, "回复内容不能为空", Toast.LENGTH_SHORT).show();
//                } else {
//                    presenter.saveReply(details.getCarId(), etContent.getText().toString());
//                    showDialog();
//                }
//                break;
            case R.id.pic_item:
                Intent intent = new Intent();
                intent.setClass(this, PlayVideoActiviy.class);
                intent.putExtra(PlayVideoActiviy.KEY_FILE_PATH, details.getVideoPath());
                startActivity(intent);
                break;
            default:
                break;
        }
    }

    private void callPhone() {
//        MPermissions.requestPermissions(this, PERMISSION_CALL, Manifest.permission.CALL_PHONE);
        rxPermissions = RxPermissions.getInstance(this);
        RxView.clicks(ivCall)
                // Ask for permissions when button is clicked
                .compose(rxPermissions.ensureEach(Manifest.permission.CALL_PHONE))
                .subscribe(new Action1<Permission>() {
                    @Override
                    public void call(Permission permission) {
                        if (permission.granted) {
                            new SweetAlertDialog(FastOnlineCheckActivity1.this, SweetAlertDialog.WARNING_TYPE)
                                    .setTitleText("提示")
                                    .setContentText(details.getTasktel())
                                    .setConfirmText("呼叫").setCancelText("取消")
                                    .setConfirmClickListener(new SweetAlertDialog.OnSweetClickListener() {
                                        @Override
                                        public void onClick(SweetAlertDialog sDialog) {
                                            sDialog.dismissWithAnimation();
                                            try {
                                                Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + details.getTasktel()));
                                                startActivity(intent);
                                            } catch (Exception exception) {
                                                MyToast.showShort("拨打电话授权被拒!");
                                            }
                                        }
                                    }).show();
                        } else if (permission.shouldShowRequestPermissionRationale) {
                            // Denied permission without ask never again
                            MyToast.showShort("拨打电话授权被拒!");
                        } else {
                            MyToast.showShort("拨打电话授权被拒!");
                        }
                    }
                });

    }


    @Override
    public void onConfigurationChanged(Configuration config) {
        super.onConfigurationChanged(config);
    }

    @Override
    public void onClick(int whichButton) {
        switch (whichButton) {
            // 相册选取
        }
    }


    @Override
    public void onCancel(DialogInterface dialog) {

    }


//    @Override
//    public void backByPhoto(UpLoadImageData item) {
//        adapter.notifyDataSetChanged();
//        dismissDialog();
//    }
//
//    @Override
//    public void toTop() {
//        myScrollview.fullScroll(ScrollView.FOCUS_UP);
//    }

    @Override
    public void showError(String error) {
        dismissDialog();
        MyToast.showShort(Constant.errr_net);
    }

//    public void saveReply(ReplyInfo info) {
//        dismissDialog();
//        if (info.getStatus() == 100) {
//            CarDetails.Reply reply = new CarDetails.Reply();
//            reply.setHeadPic(info.getHeadPic());
//            reply.setNickName(info.getNickname());
//            reply.setPassTime(info.getPassTime());
//            reply.setReplyContent(info.getDes());
////            details.getReplyList().add(0, reply);
//            details.getReplyList().add(reply);
//            etContent.setText("");
//            etContent.setText("");
//            infoAdapter.update(details.getReplyList());
//            fankuiInfo.setVisibility(View.VISIBLE);
//            fankuiInfoLine.setVisibility(View.VISIBLE);
//        } else {
//            Toast.makeText(FastOnlineCheckActivity.this, info.getMsg(), Toast.LENGTH_SHORT).show();
//        }
//    }

    @Override
    public void showresult(SuccessData result) {
        dismissDialog();
        if (result.getStatus() == 100) {
            LocalData.isRefresh = true;
            finish();
        } else {
            MyToast.showShort(result.getMsg());
        }
    }
}
